//
//  ZYImageDecodeMgr.m
//  ZYWebImage
//
//  Created by wangzhipan on 2025/3/6.
//

#import "ZYImageDecodeMgr.h"

@interface ZYImageDecodeMgr()
@property (nonatomic, strong, nullable) dispatch_queue_t queue;
@end

@implementation ZYImageDecodeMgr
+ (instancetype)sharedInstance
{
    static id _instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (instancetype)init
{
    if (self = [super init]) {
        self.queue = dispatch_queue_create("com.imagedecode.zy", DISPATCH_QUEUE_SERIAL);
    }
    return self;
}

- (void)addBlockToDo:(dispatch_block_t)block
{
    /*
     - 解码操作很耗 CPU
     - 并发解码可能导致内存暴涨
     - 串行解码更容易控制资源使用
     */
    dispatch_async(self.queue, block);
}
@end
